const CDBSave = require('./dbsave');

class Box_info extends CDBSave.CDBSave{
    constructor(){
        super();
    }

    filePath(){
        return 'box_Info_changda.json'
    }


    load(data){
        if(!data)return

        this.notices = data;
    }


    save(){
        return this.notices;
    }

    Add_boxTask(message){
        let id = this.notices.length + 1;
        message.id = id;
        let AddMessage = new Box_child(message);
        this.notices.push(AddMessage);
    }

    getTask(){
        return this.notices;
    }

    select_Task(id,number){
        for(let i=0;i<this.notices.length;i++){
            if(this.notices[i].id == id && this.notices[i].whether_finished == 0 && this.notices[i].select_paoshou == '' && this.notices[i].number != number){
                this.notices[i].select_paoshou = number;
                return 0;
            }
        }
        return -1;
    }


    Finish_BoxOrFood(id,number){
        for(let i=0;i<this.notices.length;i++){
            if(this.notices[i].id == id && this.notices[i].number == number){
                this.notices[i].whether_finished = 1;
                break;
            }
        }
    }
}


class Box_child{
    constructor(Add_boxMessage){
        this.load(Add_boxMessage)
    }

    load(data){
        this.id = data.id;
        this.number = data.number;
        this.name = data.name;
        this.intro = data.intro;
        this.telephone = data.telephone;
        this.give_Address = data.give_Address;
        this.money = data.money;
        this.time = data.time;
        this.select_paoshou = "";
        this.whether_finished = 0;
        this.type = data.type;
    }

    save(){
        return{
            id:this.id,
            number:this.number,
            name:this.name,
            intro:this.intro,
            telephone:this.telephone,
            give_Address:this.give_Address,
            money:this.money,
            time:this.time,
            select_paoshou:this.select_paoshou,
            whether_finished:this.whether_finished,
            type:this.type
        }
    }
}



module.exports = {Box_info,Box_child}